<?php

/**
 * Store 首页
 * 
 * @author Zix <zix2002@gmail.com>
 * @version 1.0 , 2015-09-10
 */

namespace Store\Controller;

use Common\Service\MerUserService;

class IndexController extends StoreController {

  public function index() {
    
    //检查参数是否接收成功
    if (empty($this->mer_id) || empty($this->wx_id)) {
      die('param error'); //未取到微信信息
    }
    
    //查看当前url  
    //echo $this->_get_cur_url();

    //取当前用户
    $user_info = $this->_get_user_info();
    
    $MerUser = MerUserService::instance();
    $data['cur_user_info'] = $MerUser->get_by_id($user_info['user_id'], TRUE);

    //取推荐人信息
    
    if ( $data['cur_user_info']['pid'] > 0 ) {
      $data['rec_user_info'] = $MerUser->get_by_id($data['cur_user_info']['pid'], TRUE);
    }
    
    //取分享相关数据
    $param = array(
      'mer_id' => $this->mer_id,
      'wx_id'  => $this->wx_id,
      'pid'    => $data['cur_user_info']['id'],
    );
    $url = U('/Store', '', TRUE, TRUE) . '?' . http_build_query($param);
    
    $data['share_data'] = array(
      'title' => '测试分享的标题',
      'desc'  => '测试分享的描述',
      'icon'  => U('Public/themes/store/images/share_img.jpg', '', TRUE, TRUE),
      'link'  => $this->WechatSdk->getOauthRedirect($url, '' , 'snsapi_userinfo'),
    );
    $data['js_config'] = $this->_get_js_config();
    
    $this->assign($data);
    $this->display();
  }
  
  function test() {
    $WechatPay = new \Common\Service\WechatPayService( 1 , 25 );
    $openid = 'oxTWIuGaIt6gTKsQRLau2M0yL16E';
    $amount = 0.01 ;
    $wishing = '感谢您参加猜灯谜活动，祝您元宵节快乐！';
    $act_name = '猜灯谜抢红包活动';
    $remark = '猜越多得越多，快来抢！';
    
    $WechatPay->send_redpack($openid, $amount, $wishing, $act_name, $remark);
  }
  
}
